<template>
	<view class="generalization">
		<view class="content">
			<empty v-if="!popularizeList.length"></empty>
			<view class="list" v-for="(item,index) in popularizeList" :key="index">
				<view class="top flex_center">
					<view class="left">
						<u-image 
							radius="12rpx"
							:src="item.content.length ? item.content[0].image : ''"
							width="144rpx"
							height="200rpx">
						  <template v-slot:loading>
						    <u-loading-icon color="red" mode="semicircle"></u-loading-icon>
						  </template>
						</u-image>
						<!-- <image :src="" mode="aspectFill"></image> -->
					</view>
					<view class="right">
						<view class="view hidden_3">{{item.profile}}</view>
						<view class="text hidden" v-if="item.content.length">{{item.content[0].content}}</view>
					</view>
				</view>

				<view class="bottom">
					<view class="text flex_r_between">
						<text>投放用户：{{item.message_num}}人</text>
						<text>已下单：{{item.order_num}}人</text>
						<view @click="toSet(item)">修改</view>
					</view>
					<view class="flex_r_around">
						<view class="bottom_btn" :style="`background: ${item.rec_show == 1 ? '#33A73B' : '#FD2A53'}`"
							@click="setPopularizeStatus(index)">
							{{
								item.rec_show == 0 ? '开始推广'
								: item.rec_show == 1 ? '停止推广'
								: item.rec_show == 2 ? '重新推广'
								: '开始推广'
							}}
						</view>
					</view>
				</view>

				<view class="status">
					{{
						item.rec_show == 1 ? '推广中'
						: item.rec_show == 2 ? '推广完成'
						: ''
					}}
				</view>
			</view>
			<view class="loading" v-if="popularizeList.length">
				<u-loadmore :status="status" />
			</view>
		</view>

		<view class="poa_btn_box">
			<view class="btn" @click="$util.toUrl('/pages/store/generalization/addAd')">+ 添加创意广告</view>
		</view>
	</view>
</template>

<script>
	import empty from '@/compentents/empty/empty.vue';
	export default {
		name: 'messageList',
		props: {

		},
		components: {
			empty
		},
		data() {
			return {
				// 创意推广列表
				popularizeList: [],
				popularizePage: 1,
				popularizeTotal: 0,

				status: 'loading',
			}
		},
		methods: {
			getList() {
				this.$get('/popularize/getPopularizeList', {
					type: 6,
					page: this.popularizePage
				}).then(res => {
					this.popularizeTotal = res.data.total;
					this.popularizeList.push(...res.data.data);
					if (this.popularizeTotal <= this.popularizeList.length) {
						this.status = 'nomore'
					}
				})
			},
			getRefresh() {
				this.popularizeList = [];
				this.popularizePage = 1;
				this.getList();
			},
			setPopularizeStatus(index) {
				// // 0=待推广，1=推广中，2=推广完成,3=推广停止
				var rec_show = 0;
				if (this.popularizeList[index].rec_show == 1) {
					rec_show = 3;
				} else {
					rec_show = 1;
				}

				this.$get('/popularize/setPopularizeStatus', {
					id: this.popularizeList[index].id,
					rec_show: rec_show,
				}).then(res => {
					this.$util.msg(res.msg);
					this.popularizeList = [];
					this.popularizePage = 1;
					this.getList();
				})
			},

			toSet(item) {
				this.$util.toUrl(`/pages/store/generalization/addAd?data=${JSON.stringify(item)}`)
			},

			getMore() {
				if (this.popularizeTotal > this.popularizeList.length) {
					this.popularizePage++;
					this.getList();
				}
			},
		},

		created() {
			// this.getList();
		}

	}
</script>

<style lang="less" scoped>
	.content {
		padding: 0 24rpx 140rpx;

		.list {
			border-radius: 24rpx;
			margin-top: 20rpx;
			overflow: hidden;
			position: relative;

			.status {
				font-weight: 500;
				font-size: 28rpx;
				color: #33A73B;
				position: absolute;
				right: 24rpx;
				top: 24rpx;
			}

			.top {
				padding: 24rpx;
				background: #FFF;

				.left {
					width: 144rpx;
					height: 200rpx;
					border-radius: 12rpx;

					image {
						width: 144rpx;
						height: 200rpx;
						border-radius: 12rpx;
					}
				}

				.right {
					width: 380rpx;
					margin-left: 14rpx;
					overflow: hidden;

					.view {
						font-weight: 500;
						font-size: 28rpx;
						color: #333333;
						line-height: 44rpx;
						margin-bottom: 10rpx;
						width: 380rpx;
					}

					.text {
						font-size: 26rpx;
						color: #666666;
						width: 380rpx;
					}
				}
			}

			.bottom {
				padding: 16rpx 24rpx 28rpx;
				background: #FFF6D9;

				.text {
					text {
						font-weight: 500;
						font-size: 26rpx;
						color: #A85900;
						line-height: 36rpx;
					}

					view {
						font-weight: 500;
						font-size: 26rpx;
						color: #FD2A53;
						line-height: 36rpx;
					}
				}

				.bottom_btn {
					width: 320rpx;
					height: 80rpx;
					background: #FD2A53;
					border-radius: 42rpx;
					font-weight: 500;
					font-size: 28rpx;
					color: #FFFFFF;
					line-height: 80rpx;
					text-align: center;
					margin-top: 24rpx;
				}
			}
		}
	}

	.poa_btn_box {
		padding: 0 24rpx;
		width: 100vw;
		position: fixed;
		bottom: 30rpx;
		left: 0;
		z-index: 60;

		.btn {
			height: 100rpx;
			background: #FFF7F8;
			border-radius: 24rpx;
			border: 2rpx solid #FD2A53;
			font-weight: 500;
			font-size: 28rpx;
			color: #FD2A53;
			line-height: 100rpx;
			text-align: center;
		}
	}
</style>